<?php

class email extends CI_Model {

    function index() {
        $q = $this->db->get('email');
        return $q;
    }

    function show($id) {
        $this->db->where('id', $id);
        $q = $this->db->get('email');
        return $q;
    }

    function edit($id) {
        $this->db->where('id', $id);
        $q = $this->db->get('email');
        return $q;
    }

    function create($email) {
        $data = array(
            'email' => $email,
        );
        $this->db->insert('email', $data);
        redirect('emails/index');
    }

    function update($id, $email) {
        $data = array(
            'email' => $email,
        );
        $this->db->where('id', $id);
        $this->db->update('email', $data);
        redirect('emails/index');
    }

    function admin() {
        $q = $this->db->get('email');
        return $q;
    }

    function get_email() {
        $q = $this->db->get('email');
        foreach ($q->result() as $row) {
            return $row->email;
        }
    }

    function email_array() {
        $query = $this->db->get('email');
//        foreach($query->result_array() as $row){
//            return $row->email; 
//        }
//        return $query->result_array();
//        if ($query->num_rows() > 0) {
//            $row = $query->row_array();
//            return $row;
//        }
        $i =0;
        foreach ($query->result_array() as $row) {
//            $data{$row['code']} = $row['nama'] . ' (' . $row['code'] . ')';
            $data{$i} = $row['email'];
            $i++;
        }
        return $data;
    }

}

?>
